﻿function getParams() {

    var params = {};

    var companyName = $("input[name='companyName']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(companyName)) {
        params.companyName = companyName;
    }

    var bankName = $("input[name='bankName']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(bankName)) {
        params.bankName = bankName;
    }

    var cardNumber = $("input[name='cardNumber']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(cardNumber)) {
        params.cardNumber = cardNumber;
    }

    var cardName = $("input[name='cardName']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(cardName)) {
        params.cardName = cardName;
    }

    var startTime = $("input[name='startTime']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(startTime)) {
        params.startTime = startTime;
    }

    var endTime = $("input[name='endTime']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(endTime)) {
        params.endTime = endTime;
    }

    return params;
}

function replace_field(key) {

    var data = {
        "公司名称": "Company Name",
        "银行名称": "Bank Name",
        "用户名": "Username",
        "银行卡号": "Card Number",
        "金额": "Amount",
        "余额变化前": "Before Change",
        "余额变化后": "After Change",
        "新增者": "Creator",
        "类别": "Category",
        "新增时间": "Added Time",
        "订单号": "Order#",
        "新增说明": "Description"
    };

    var language = FlashPay.Util.Language();

    if (!FlashPay.Util.isNullOrEmptySpance(language) && language == "en") {
        return data[key];
    } else {
        return key;
    }
}

function doSearch() {
    $("#receiptAdjustBalance").datagrid({
        fit: false,
        loadMsg: '数据加载中，请稍后……',
        ctrId: 'easyui-treegrid',
        url: '/Payment/ReceiptAdjustBalance',
        queryParams: getParams(),
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        pageSize: pageSize,
        pageList: [15, 30, 50, 100, 1000],
        height: $(window).height() - 70,
        idField: 'bcId',
        onLoadSuccess: function () {
            pageSize = $('#receiptAdjustBalance').datagrid('options').pageSize;
        },
        columns: [[
            { field: 'companyName', title: replace_field('公司名称'), width: 100, align: 'left' },
            { field: 'bankName', title: replace_field('银行名称'), width: 100, align: 'left' },
            { field: 'cardName', title: replace_field('用户名'), width: 65, align: 'left' },
            {
                field: 'cardNumber',
                title: replace_field('银行卡号'),
                width: 125,
                align: 'left',
                formatter: function (val, row) {
                    return FlashPay.Util.SubCardNumber(val);
                }
            },
            { field: 'amount', title: replace_field('金额'), width: 100, align: 'right' },
            { field: 'beforeBalance', title: replace_field('余额变化前'), width: 100, align: 'right' },
            { field: 'afterBalance', title: replace_field('余额变化后'), width: 100, align: 'right' },
            { field: 'createName', title: replace_field('新增者'), width: 100, align: 'left' },
            {
                field: 'adjustStatus',
                title: replace_field('类别'),
                width: 65,
                align: 'left',
                formatter: function (val, row) {
                    return FlashPay.Util.GetAdjustStatusValue(val);
                }
            },
            { field: 'createDBDate', title: replace_field('新增时间'), width: 170, align: 'left' },
            { field: 'orderNo', title: replace_field('订单号'), width: 130, align: 'left' },
            { field: 'createRemark', title: replace_field('新增说明'), width: 100, align: 'left' }
        ]]
    });
}